const path = require('path')
const buildPath = path.resolve(__dirname, 'dist')
const ExtractTextPlugin = require('extract-text-webpack-plugin')

module.exports = (webpackConfig, env) => {
  console.log('webpack-config', webpackConfig)
  webpackConfig.module.rules.map((item) => {
    if (String(item.loader).indexOf('url-loader') >= 0) {
      item.options = Object.assign({}, item.options, {
        limit: 10000,
        name: 'static/images/[name].[hash:8].[ext]'
      })
    }
    return item
  })
  webpackConfig.output = {
     path: buildPath,
     pathinfo: false,
     filename: 'static/js/[name].[hash:8].js',
     publicPath: '/',
     chunkFilename: 'static/js/[name].async.[hash].js'
  }
  webpackConfig.plugins.map((item) => {
    if (item instanceof ExtractTextPlugin) {
      item.filename = 'static/css/app.[hash:8].css'
    }
    return item
  })
  console.log('111', webpackConfig.plugins)

  return webpackConfig
}
